package control
{
	import flash.events.Event;
	
	import model.ModelLocator;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	import view.Markers;
	import view.MyInforWindow;
	
	import vo.MyMarker;
	public class AddMarker
	{
		internal var theModel:ModelLocator = ModelLocator.getInstance();
		private var AddMarkerRO:RemoteObject;
		public var mark:view.Markers;
		public var info:view.MyInforWindow;
		public function AddMarker(mark:view.Markers,infowin:view.MyInforWindow)
		{
			this.mark = mark;
			this.info = infowin;
			AddMarkerRO = new RemoteObject();
			AddMarkerRO.destination="AddMarker";
			AddMarkerRO.doAddMarker.addEventListener(ResultEvent.RESULT,AddMarkerResultHandler);
			AddMarkerRO.addEventListener(FaultEvent.FAULT, AddMarkerFaultHandler);
		}
		
		public function doAddMarker(marker:MyMarker):void
		{
			AddMarkerRO.doAddMarker(marker,theModel.user.user_id,mark.searchtype.text);
		}
		
		internal function AddMarkerResultHandler(event:ResultEvent):void
		{
				//Alert.show("Add marker Successfully.");
				theModel.allTheTypeMarkers = event.result.markers as ArrayCollection;
				
				theModel.tempmarker = event.result.marker;
				this.info.marker.id = event.result.marker['id'];
				theModel.dispatchEvent(new Event(ModelLocator.ADDMARKER_OK));
				 	
		}
		
		internal function AddMarkerFaultHandler(event:FaultEvent):void
		{
			Alert.show("error occur when add marker");
		}
	}
}